package com.cxs.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @Project: jdbc
 * @Author: cxs2014501@163.com
 * @Create: 2022/8/31 16:20
 * @Description:
 **/
public class FileReadUtil {

    public static InputStream getFileAsStream(String filePath){
        InputStream in = null;
        File file = null;

        if (in == null) {
            try {
                file = new File("." + File.separator + "config" + File.separator + filePath);
                if (file.exists()) {
                    in = new FileInputStream(file);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        if (in == null) {
            try {
                file = new File("." + File.separator + filePath);
                if (file.exists()) {
                    in = new FileInputStream(file);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        if (in == null) {
            in = FileReadUtil.class.getClassLoader().getResourceAsStream(filePath);
        }
        return in;
    }
}
